import Vue from "vue";
import VueRouter from "vue-router";
import Nprogress from 'nprogress';
import 'nprogress/nprogress.css';

// 组件
import Home from "../views/Home.vue";
import Find from '../views/Find.vue';
import Register from '../views/Register.vue';
import Login from '../views/Login.vue';
import NoFound from '../views/NoFound.vue';
import My from '../views/My/My.vue';
import NewPassword from '../views/My/NewPassword.vue';
import Publish from '../views/My/Publish.vue';
import PublishVideo from '../views/My/PublishVideo.vue';
import Collection from '../views/Collection.vue';
import Album from '../views/Album.vue';
import AlbumInfo from '../views/AlbumInfo.vue';
import Video from '../views/Video.vue';
import Search from '../views/Search.vue';
import Acticle from '../views/Acticle.vue';
import ActicleInfo from '../views/ActicleInfo.vue';
import HouTai from '../views/HouTai.vue';
import Focus from '../views/HouTai/Focus.vue';
import SetRole from '../views/HouTai/SetRole.vue';
import AddUser from '../views/HouTai/AddUser.vue';
import Imgs from '../views/HouTai/Imgs.vue';
import RemoveAlbum from '../views/HouTai/RemoveAlbum.vue';
import RemoveActicle from '../views/HouTai/RemoveActicle.vue';


Vue.use(VueRouter);

const routes = [
  { path: "/", redirect: "/home" },
  { path: "/home", component: Home },
  { path: "/find", component: Find },
  { path: "/register", component: Register },
  { path: "/login", component: Login },
  { path: "/my", component: My },
  { path: "/newPassword", component: NewPassword },
  { path: "/publish", component: Publish },
  { path: "/publish/video", component: PublishVideo },
  { path: "/collection", component: Collection },
  { path: "/album", component: Album },
  { path: "/album/:id", component: AlbumInfo },
  { path: "/video", component: Video },
  { path: "/search", component: Search },
  { path: "/acticle", component: Acticle },
  { path: "/acticle/:id", component: ActicleInfo },
  { 
    path: "/houTai", component: HouTai, redirect: '/focus',
    children: [
      { path: '/focus', component: Focus },
      { path: '/set/role', component: SetRole },
      { path: '/add/user', component: AddUser },
      { path: '/img/option', component: Imgs },
      { path: '/remove/album', component: RemoveAlbum },
      { path: '/remove/acticle', component: RemoveActicle },
    ]
  },
  { path: "/nofound", component: NoFound },
  { path: '*', redirect: '/nofound' },
];

const router = new VueRouter({
  routes,
  linkActiveClass: "current-nav",
});

router.beforeEach((to, from, next) => {
  Nprogress.start();
  document.title = '天真小站';
  next();
})

router.afterEach(() => {
  Nprogress.done();
});


const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

export default router;
